package com.healthy.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.healthy.entity.YgWallet;
import com.healthy.mapper.YgWalletMapper;
import com.healthy.service.YgWalletService;

@Service
@Transactional
public class YgWalletServiceImpl implements YgWalletService{

	@Autowired
	private YgWalletMapper ywm;
	
	/*
	 * 用户查询本人账户余额及积分
	 * @see com.healthy.service.YgWalletService#queryWalletByUid(java.lang.String)
	 */
	@Override
	public JSONObject queryWalletByUid(String user_id) {
		JSONObject json = new JSONObject();
		String msg = "查询失败，当前系统业务繁忙，请稍后再试"; 
		int status = -1;
		YgWallet yw = ywm.queryUserSurplusByUid(user_id);
		if( yw != null){
			json.put("surplus", yw.getSurplus());
			json.put("integral", yw.getIntegral());
			status = 1;
			msg = "查询成功，数据返回";
		}
		json.put("status", status);
		json.put("msg", msg);
		return json;
	}

	@Override
	public boolean updateUserSurplus(YgWallet ygWallet) {
		return this.ywm.updateUserSurplus(ygWallet) > 0;
	}

}
